export default {
  namespaced: true,
  state: {
    token: localStorage.getItem('token') || '',
    user: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')) : {},
    role: localStorage.getItem('role') || ''
  },
  mutations: {
    // 登录成功 存缓存
    LOGIN_USER (state, { token, user, role }) {
      state.token = token
      state.user = user
      state.role = role
    },
    // 退出登录清缓存
    CLEAR_USER (state) {
      state.token = ''
      state.user = {}
      state.role = ''
      localStorage.removeItem('token')
      localStorage.removeItem('user')
      localStorage.removeItem('role')
      // 清除上次缓存的navtabs
      sessionStorage.removeItem('navTabs')
    }
  }
}
